#include <iostream>

#include "01_FactoryPattern.cpp"
#include "02_AbstractFactory.cpp"
#include "03_SingletonPattern.cpp"

void TestFactoryPattern();
void TestAbstractFactory();
void TestSingletonPattern();

int main() {
    //01 工厂模式
    TestFactoryPattern();

    //02 抽象工厂模式
    TestAbstractFactory();

    //03 单例模式
    TestSingletonPattern();

    return 0;
}

void TestFactoryPattern() {
    Fruit *fruit = FruitFactory::createFruit("apple");
    if (fruit == nullptr) {
        std::cout << "create fruit failed" << std::endl;
        return;
    }
    fruit->show();
    delete fruit;
}

void TestAbstractFactory() {
    AbstractFactory* factory = ObjectFactory::getFactory("Shape");
    Shape* shape = factory->getShape("Rectangle");
    shape->draw();

    factory = ObjectFactory::getFactory("Color");
    Color* color = factory->getColor("Red");
    color->fill();
}

void TestSingletonPattern() {
    Singleton &singleton = Singleton::getInstance();
    singleton.show();
}

